Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Multi chain adapter #500

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

[DRAFT] Multi chain adapter #500

wants to merge 10 commits into from

Conversation

0xmaayan
Copy link
Collaborator

@0xmaayan 0xmaayan commented Mar 10, 2025

Introducing different packages to handle cross-chain functionalities, that can be used to build and support a cross-chain adapter in any dapp.
Each package can be used as a standalone component, and the dapp should decide what packages it needs following its business logic.

Live example https://aptos-labs.github.io/aptos-wallet-adapter/nextjs-example-testing/swap

wallet-adapter-aggregator:
A folder that contains multiple packages, each represents a Wallet. In addition, it holds a wallet-adapter-aggregator-core package that holds the abstract class that each wallet must implement.
I implemented a conversion layer for each cross-chain wallet, to represent it as the official Aptos wallet standard. There are some issues I have seen, and I am open for any suggestions.

  • The Aptos wallet standard defines input and output types, and expects each feature to follow it. That becomes a bit difficult when trying to convert each wallet function/feature.
  • Overall, for Solana and I believe other future chains we can handle the types, but when it comes to EVM it is more complex. For example, returning AccountInfo from the connect() or getAccount() methods, is almost impossible because 1) this class represents an Aptos account (and therefore a 32 byte account) and 2) there is no way to retrieve the connected account publicKey from the account address (unless you submitted a transaction)

I am open for any implementation suggestions.

cross-chain-core:
A package that holds a cross-chain logic. Currently only provides CCTP transfer logic with Wormhole as the provider. In the Future, we will support more providers (LayerZero, Cellar, etc) and add it to that package.
In addition, this package can expose some related APIs like getAccountUsdcBalance() (still debating whether this should live in this package, or be part of the wallet features).

The CrossChainCore class accepts different dapp properties

  • network: Network; // the network to use
  • disableTelemetry?: boolean;

And the startCCTPTransfer() method in the WormholeProvider class accepts

  • sourceChain: Chain;
  • wallet: AdapterWallet;
  • destinationAddress: AccountAddressInput;
  • mainSigner: Account;
  • sponsorAccount?: Account | Partial<Record<Network, string>>; // a generated account or gas station key

cross-chain-react
A React state provider that uses

  • The cross-chain-core package
  • The wallet aggregator package the dapp wants to support

Next steps:

@BriungRi
Copy link
Contributor

You can simplify the nextjs example by having the button for Sepolia Solana or Sui open the connect wallet modal for those wallets


export type AptosAccount = Account;

export type Chain = "Solana" | "Ethereum" | "Sui" | "Aptos";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not enum?

export type UsdcBalance = {
amount: string;
decimal: number;
display: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I would implement display in this component. I think better to let the developer choose how they want to display. I think it just gets complicated because

  1. Developer might want to only use period to dilineate decimals, while others may want to use comma
  2. Developer might want to use some kind of significant figures logic

Just think it's not a good idea to put it in this package because it is hard to undo these decisions later


import { ChainsConfig } from "../types";

export const mainnetChains: ChainsConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reference link to where these values come from? Would be nice to leave as comments

@hardsetting
Copy link
Contributor

Took a good look, great work!
I have some high-level ideas I'd love to chat about when you have time

The flow I was hoping to see was something similar to this (hopefully you have access):
https://excalidraw.com/#json=dtzELJ8ezex0lWN18D-F1,3dKp9B39GvEuf4tifqTOQw

@0xmaayan
Copy link
Collaborator Author

You can simplify the nextjs example by having the button for Sepolia Solana or Sui open the connect wallet modal for those wallets

That brings up questions around multi chain wallets. For example, Nightly which is a wallet that supports all those chains.
I rather leave it to the dapp to decide how it wants to display the wallets in its own WalletSelector implementation

@0xmaayan 0xmaayan force-pushed the multi_chain branch 3 times, most recently from c135d6b to c823561 Compare March 14, 2025 15:18
@0xmaayan 0xmaayan force-pushed the multi_chain branch 2 times, most recently from 9b930b0 to bdc6d69 Compare March 18, 2025 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants